package com.gewu.pm.ui.adapter.customer;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;

/**
 * 业务员详情 - 终端列表适配器
 */
public class SalespersonTerminalAdapter extends AppAdapter<String> {

    public SalespersonTerminalAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new TerminalViewHolder();
    }

    private final class TerminalViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView mTerminalNameView;
        private final TextView mTerminalAddressView;
        private final TextView mTerminalCodeView;
        private final TextView mTerminalTypeView;
        private final TextView mVehicleCodeView;
        private final TextView mDistributorView;
        private final TextView mSalespersonView;
        private final TextView mHasArrearsView;

        private TerminalViewHolder() {
            super(R.layout.salesperson_terminal_item);
            mTerminalNameView = findViewById(R.id.tv_terminal_name);
            mTerminalAddressView = findViewById(R.id.tv_terminal_address);
            mTerminalCodeView = findViewById(R.id.tv_terminal_code);
            mTerminalTypeView = findViewById(R.id.tv_terminal_type);
            mVehicleCodeView = findViewById(R.id.tv_vehicle_code);
            mDistributorView = findViewById(R.id.tv_distributor);
            mSalespersonView = findViewById(R.id.tv_salesperson);
            mHasArrearsView = findViewById(R.id.tv_has_arrears);
        }

        @Override
        public void onBindView(int position) {
            String terminalName = getItem(position);
            
            // 设置终端名称
            mTerminalNameView.setText(terminalName);
            
            // TODO: 后期使用完整Bean对象替换
            // 当前显示测试数据
            mTerminalAddressView.setText("伟业路298号（伟业地铁站A口步行460米）");
            mTerminalCodeView.setText("POS000000000006");
            mTerminalTypeView.setText("农贸");
            mVehicleCodeView.setText("A12233");
            mDistributorView.setText("xx-配送商（杭州小配送1号车）");
            mSalespersonView.setText("震辉");
            
            // 根据位置模拟显示"有欠款"标签（第一个显示）
            if (position == 0) {
                mHasArrearsView.setVisibility(android.view.View.VISIBLE);
            } else {
                mHasArrearsView.setVisibility(android.view.View.GONE);
            }
        }
    }
}

